package com.job.ZhangMeng.Homework0715;

import java.util.Arrays;

public class StringConstructor {

    public static void main(String[] args) {
        byte[] bytes={97,98,99,100,101,102};
        String s1=new String(bytes);    //根据unicode编码转换为对应字符
        System.out.println(s1);

        String s2=new String(bytes,1,3);    //从bytes[1]到bytes[3]
        System.out.println(s2);

        char[] chars={'A','我',66,'!','=','你'};  //66转化为'B'
        System.out.println(new String(chars));
        String s3=new String(chars,3,3);    //从chars[3]到chars[5]
        System.out.println(s3);

        String name="卢比扬卡包吃住";  //UTF-8,一个汉字占3字节
        byte[] nameBytes=name.getBytes();
        System.out.println(Arrays.toString(nameBytes)); //3数1汉字
        char[] chars1=name.toCharArray();
        System.out.println(Arrays.toString(chars1));

        char c=name.charAt(3);  //获取name的第4个字,即chars1[3]
        System.out.println(c);
        System.out.println(name.length());  //获取name的长度,即字符个数
        for (int i = 0; i < name.length(); i++) {
            System.out.println(i+"="+name.charAt(i));
        }

        String str="public class StringConstructor";
        int count=0;
        for (int i = 0; i < str.length(); i++) {
            if(Character.isUpperCase(str.charAt(i)))    //求大写字母个数,比较编码值
                count++;
        }
        System.out.println(count);
    }

}
